package at.jaki.ubb.crawling.components;

import java.util.ArrayList;
import java.util.List;

import at.jaki.ubb.crawling.api.filters.FilterResult;

/**
 * Generic class used to manage filters.
 * 
 * @author Attila Jakabfi
 * 
 * @param T generic type of filterable element
 */
public class FilterChain<T> {

	private List<CEFilterWrapper<T>> filters = new ArrayList<CEFilterWrapper<T>>();

	public void addFilter(CEFilterWrapper<T> filter) {
		filters.add(filter);
	}

	public FilterResult doFilter(T t) {
		for (CEFilterWrapper<T> filter : filters) {
			FilterResult res = filter.doFilter(t);

			// in case of drop or return, end the chain
			if (FilterResult.CONTINIUE != res) {
				return res;
			}
		}
		// once chain has finished we can continue
		return FilterResult.CONTINIUE;
	}

}
